package ui;

import java.awt.CardLayout;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import controller.ATM;
import data.BankDatabaseUserSQL;

/** Represents the main screen of the ATM, 
 * extended by JFrame. The class is instantiating all
 * UIs of the program, meanwhile giving it a constant
 * Furthermore the class has public methods for each 
 * UI object, in order to access the UI objects from other classes
 * @author Matthias
 */ 
public class Screen extends JFrame {

	//////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	///////////////// Constants for all GUIs \\\\\\\\\\\\\\\\\\\\\\\\\\\
	
	/** String constant for Welcome **/
	public static final String WELCOME = "welcome";
	/** String constant for AdmMenu **/
	public static final String ADMMENU = "adminmenu";
	/** String constant for AdmCreate **/
	public static final String ADMCREATE = "admincreate";
	/** String constant for AdmEdit **/
	public static final String ADMEDIT = "adminedit";
	/** String constant for AdmDelete **/
	public static final String ADMDELETE = "admindelete";
	/** String constant for AdmView **/
	public static final String ADMVIEW = "adminview";
	/** String constant for ChoiceAcc **/
	public static final String CHOICEACC = "choiceaccount";
	/** String constant for AccMenu **/
	public static final String ACCMENU = "accountmenu";
	/** String constant for AccDeposit **/
	public static final String ACCDEPOSIT = "accountdeposit";
	/** String constant for AccWithdrawal **/
	public static final String ACCWITHDRAWAL = "accountwithdrawal";
	/** String constant for AccInterestRate **/
	public static final String ACCINTERESTRATE = "accountinterestrate";
	/** String constant for AccAccountInfo **/
	public static final String ACCACCOUNTINFO = "accountbalanceinquiry";
	/** String constant for UserMenu **/
	public static final String USERMENU = "usermenu";
	/** String constant for UserMenuAdd **/
	public static final String USERMENUADD = "usermenuadd";
	/** String constant for UserMenuDelete **/
	public static final String USERMENUDELETE = "usermenudelete";
	/** String constant for UserMenuViewAcc **/
	public static final String USERMENUVIEWACC = "usermenuviewacc";
	
	//////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	/////// Declaring all the UI Objects with their given types \\\\\\\\
	
	/**
	 * 
	 */
	private final JPanel contentPane;
	
	/**
	 * 
	 */
	private final Welcome welcome;
	
	/**
	 * 
	 */
	private AdmMenu adminmenu;
	
	/**
	 * 
	 */
	private AdmCreate admincreate;
	
	/**
	 * 
	 */
	private AdmEdit adminedit;
	
	/**
	 * 
	 */
	private AdmDelete admindelete;
	
	/**
	 * 
	 */
	private AdmView adminview;
	
	/**
	 * 
	 */
	private ChoiceAcc choiceacc;
	
	/**
	 * 
	 */
	private AccMenu accountmenu;
	
	/**
	 * 
	 */
	private AccDeposit accountdeposit;
	
	/**
	 * 
	 */
	private AccWithdrawal accountwithdrawal;
	
	/**
	 * 
	 */
	private AccInterestRate accountinterestrate;
	
	/**
	 * 
	 */
	private AccAccountInfo accountAccountInfo;
	
	/**
	 * Declaring the UserMenu object with type usermenu
	 */
	private UserMenu usermenu;
	/**
	 * Declaring the ATM object with type atm
	 */
	private UserMenuAdd usermenuadd;
	
	/**
	 * Declaring the ATM object with type atm
	 */
	private UserMenuDelete usermenudelete;
	
	/**
	 * Declaring the ATM object with type atm
	 */
	private UserMenuViewAcc usermenuviewacc;
	
	/**
	 * Declaring the ATM object with type atm
	 */
	private final ATM atm;
	
	/**
	 * Declaring the BankDatabaseUserSQL object with type bdbUserSQL
	 */
	private BankDatabaseUserSQL bdbUserSQL;
	
	/** Declaring a CardLayout object for the type
	 * cardlay. Allowing the user of the program
	 * to flip through various GUIs.
	 */
	private final CardLayout cardlay;
	
	/** Constructor of Screen, is instantiating 
	 * the contentpane to be a JPanel, and setting 
	 * the layout of it to be a CardLayout, allowing 
	 * the user to flip between the UIs.
	 * Also it is instantiating the Welcome screen
	 * @param atm
	 */
	public Screen(final ATM atm) {
		
		setIconImage(Toolkit.getDefaultToolkit().
				getImage(Screen.class.getResource("/pic/LOGO Mini.png")));
		
		this.atm = atm;

		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setTitle("Automated Teller Machine");
		setBounds(0, 0, 600, 480);
		setLocation(350, 200);

		contentPane = new JPanel();
		setContentPane(contentPane);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new CardLayout());

		welcome = new Welcome();
		contentPane.add(welcome, WELCOME);
		cardlay = (CardLayout) getContentPane().getLayout();
	}
	
	/** This method instantiates 
	 * various ui, and adding them 
	 * to the contentpane
	 */
	public final void initGUIs() {

		adminmenu = new AdmMenu();
		contentPane.add(adminmenu, ADMMENU);

		admincreate = new AdmCreate();
		contentPane.add(admincreate, ADMCREATE);
		
		adminedit = new AdmEdit(this);
		contentPane.add(adminedit, ADMEDIT);

		accountmenu = new AccMenu();
		contentPane.add(accountmenu, ACCMENU);

		accountdeposit = new AccDeposit();
		contentPane.add(accountdeposit, ACCDEPOSIT);

		accountwithdrawal = new AccWithdrawal();
		contentPane.add(accountwithdrawal, ACCWITHDRAWAL);

		accountinterestrate = new AccInterestRate();
		contentPane.add(accountinterestrate, ACCINTERESTRATE);

		accountAccountInfo = new AccAccountInfo();
		contentPane.add(accountAccountInfo, ACCACCOUNTINFO);

		usermenu = new UserMenu();
		contentPane.add(usermenu, USERMENU);

		usermenuadd = new UserMenuAdd();
		contentPane.add(usermenuadd, USERMENUADD);
	}
	
	/** This method is instantiating the ui 
	 * AdminDelete and adding the parameter of ATM object
	 * @param atm
	 */
	public final void addAdminDelete(final ATM atm) {
		admindelete = new AdmDelete(this);
		contentPane.add(admindelete, ADMDELETE);
	}
	
	/** This method is instantiating the ui 
	 * AdmView and adding the parameter of ATM object
	 * @param atm referring to the ATM object
	 */
	public final void addAdminView (final ATM atm) {
		this.bdbUserSQL = atm.getClassBdbUserSQL();
		adminview = new AdmView(bdbUserSQL);
		contentPane.add(adminview, ADMVIEW);
	}
	
	/** This method is instantiating the ui 
	 * UserMenuViewAcc and adding the parameter of ATM object
	 * @param atm referring to the ATM object
	 */
	public final void addUserMenuViewAcc (final ATM atm) {
		usermenuviewacc = new UserMenuViewAcc(this);
		contentPane.add(usermenuviewacc, USERMENUVIEWACC);
	}
	
	/** This method is instantiating the ui 
	 * UserMenuDelete and adding the parameter of ATM object
	 * @param atm referring to the ATM object
	 */
	public final void addUserMenuDelete(final ATM atm) {
		usermenudelete = new UserMenuDelete(this);
		contentPane.add(usermenudelete, USERMENUDELETE);
	}
	
	/**
	 * @param atm 	referring to the ATM object
	 */
	public final void addChoiceAcc(final ATM atm) {
		choiceacc = new ChoiceAcc(this);
		contentPane.add(choiceacc, CHOICEACC);
	}
	
	/**
	 * @return Welcome object
	 */
	public final Welcome getWelcome() {
		return welcome;
	}
	
	/**
	 * @return AdmMenu object
	 */
	public final AdmMenu getAdmMenu() {
		return adminmenu;
	}
	
	/**
	 * @return AdmCreate object
	 */
	public final AdmCreate getAdmCreate() {
		return admincreate;
	}
	
	/**
	 * @return AdmDelete object 
	 */
	public final AdmEdit getAdmEdit() {
		return adminedit;
	}
	
	/**
	 * @return AdmDelete object
	 */
	public final AdmDelete getAdmDelete() {
		return admindelete;
	}
	
	/**
	 * @return AdmView object
	 */
	public final AdmView getAdmView() {
		return adminview;
	}
	
	/**
	 * @return ChoiceAcc object
	 */
	public final ChoiceAcc getChoiceAcc() {
		return choiceacc;
	}
	
	/**
	 * @return AccMenu object
	 */
	public final AccMenu getAccMenu() {
		return accountmenu;
	} 
	
	/**
	 * @return AccDeposit object
	 */
	public final AccDeposit getAccDeposit() {
		return accountdeposit;
	}
	
	/**
	 * @return AccWithdrawal object
	 */
	public final AccWithdrawal getAccWithdrawal() {
		return accountwithdrawal;
	}
	
	/**
	 * @return AccInterestRate object
	 */
	public final AccInterestRate getAccInterestRate() {
		return accountinterestrate;
	}
	
	/**
	 * @return AccAccountInfo object
	 */
	public final AccAccountInfo getAccAccountInfo() {
		return accountAccountInfo;
	}
	
	/**
	 * @return UserMenu object
	 */
	public final UserMenu getUserMenu() {
		return usermenu;
	}
	
	/**
	 * @return UserMenuAdd object
	 */
	public final UserMenuAdd getUserMenuAdd() {
		return usermenuadd;
	}
	
	/**
	 * @return UserMenuDelete object
	 */
	public final UserMenuDelete getUserMenuDelete() {
		return usermenudelete;
	}
	
	/**
	 * @return UserMenuViewAcc object 
	 */
	public final UserMenuViewAcc getUserMenuViewAcc() {
		return usermenuviewacc;
	}
	
	/**
	 * @param card
	 */
	public final void show(final String card) {
		cardlay.show(this.getContentPane(), card);
	}
	
	/**
	 * @return ATM object
	 */
	public final ATM getClassATM() {
		return atm;
	}

} // end class Screen